package com.cat.model.common.util;

import com.alonew.json.JSONException;
import com.alonew.json.JSONObject;

public enum ErrorCode {

    OK(0, "ok"), //
    NOT_LOGIN(1000, "用户未登陆"), //
    TOKEN_ERROR(1001, "token已过期"), //
    USER_NOT_EXIST(1002, "用户不存在"), //
    USER_EXIST(1002, "用户已存在"), //
    PARAM_INVALID(1003, "param invalid"), //
    SIGN_INVALID(5001, "sign invalid"), //
    RESOURCE_NO_EXIST(1004, "resource no exist"), //
    
    PARAM_ERROR(2001, "请求参数有误"), //
    SERVER_ERROR(2002, "服务器异常"), //
    
    PHONE_SENDSMS_UNSUPPORT(2004, "手机号码不支持接收下发短信"),
    PHONE_INVALID(2005, "电话号码格式错误"),
    CHECK_CODE_INVAILD(2006, "验证码校验失败"),
	CHECK_CODE_EXPIRE(2007, "验证码过期"),
	TOKEN_EXPIRE(2008, "TOKEN过期"),
	REFRESH_TOKEN_EXPIRE(2009, "REFRESHTOKEN过期"),
	PHONE_BINDED(2010, "该手机号码已绑定过"),
	RESERVATION_STATUS_ERROR(2011, "该预约单未受理，请确认"), 
	RESERVATION_STATUS_SURE_ERROR(2011, "该预约单已确认"), 
	RESERVATION_STATUS_PAY_ERROR(2011, "该预约单已支付"), 
	RESERVATION_STATUS_CANCEL_ERROR(2011, "该预约单已取消"), 
	ORDERNUM_NOFOUND_ERROR(2012, "该订单号不存在，请确认"), 
	BASORDER_STATUS_ERROR(2013, "该订单状态已变化，请确认"), 
	app_STATUS_ERROR(2015, "审核已通过，无法修改"), 

	ILLEGAL_OPERATION(2014, "非法操作"), 
	
	PASSWORD_ERROR(2109, "密码错误"),
    ;

    private final int    ret;
    private final String msg;

    private ErrorCode(int ret, String msg) {
        this.ret = ret;
        this.msg = msg;
    }

    @Override
    public String toString() {
        return ret + "," + msg;
    }

    public int getRet() {
        return ret;
    }

    public String getMsg() {
        return msg;
    }

    public JSONObject responseJSON() {
        JSONObject json = new JSONObject();
        try {
            json.put("result", getRet());
            json.put("msg", getMsg());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return json;
    }

    public String response() {
        return responseJSON().toString();
    }
    
    public ResultJson resultJson() {
    	ResultJson resultJson = new ResultJson();
    	resultJson.setMsg(msg);
    	resultJson.setRet(ret);
        return resultJson;
    }
}